package com.ssm.basis.web.servlet.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.util.ContentCachingRequestWrapper;

import javax.servlet.*;
import java.io.IOException;

/**
 * @see ServletRegistrationBean
 * @see FilterRegistrationBean
 * @see ServletListenerRegistrationBean
 * https://blog.csdn.net/f641385712/article/details/86554854
 * 不要在 Filter 里提前去 getInputStream()，否则 @RequestBody 将拿不到东西而报错
 * @see ContentCachingRequestWrapper
 * https://blog.csdn.net/f641385712/article/details/87814153
 * https://blog.csdn.net/qq_35067322/article/details/102720567
 */
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
// @Component
// @WebFilter(urlPatterns = "/*", asyncSupported = true)
public class EmptyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        filterConfig.getFilterName();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        log.debug("destory");
    }
}